package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译SQL完成下面的工作
 * 根据用户名,修改用户的密码
 */
public class JDBCDemo10 {
    public static void main(String[] args) {
        //需求:根据用户名修改用户的密码，昵称，年龄
        try (Connection connection = DBUtil.getConnection();){
            String sql = "UPDATE user " +
                    "SET password=?,nickname=?,age=? " +
                    "WHERE username=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"202506");
            ps.setString(2,"你能我吃");
            ps.setInt(3,16);
            ps.setString(4,"徐毅");
            int num = ps.executeUpdate();
            System.out.println(num>0?"修改成功":"修改失败");

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}